
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/lib/font-awesome-4.7.0/css/font-awesome.css" media="all">
    <link rel="stylesheet" href="../static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">


        <script type="text/html" id="toolbarDemo">
<%--            <div class="layui-btn-container">--%>
<%--                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">--%>
<%--                    <i class="fa fa-plus"></i>--%>
<%--                    添加 </button>--%>
<%--                <button class="layui-btn  layui-btn-sm data-edit-btn" lay-event="edit">--%>
<%--                    <i class="fa fa-pencil"></i>修改 </button>--%>
<%--                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete">--%>
<%--                    <i class="fa fa-remove"></i>删除 </button>--%>
<%--                <button class="layui-btn layui-btn-sm layui-btn-sm data-delete-btn" lay-event="editque">--%>
<%--                    <i class="fa fa-remove"></i>设计问卷</button>--%>
                <button class="layui-btn layui-btn-sm layui-btn-sm data-delete-btn" lay-event="preview">
                    <i class="fa fa-search"></i>
                    预览问卷 </button>
<%--                <button class="layui-btn layui-btn-sm layui-btn-sm data-delete-btn" lay-event="publish">--%>
<%--                    <i class="fa fa-list"></i>--%>
<%--                    发布问卷 </button>--%>
<%--            </div>--%>
        </script>

        <table class="layui-hide layui-anim layui-anim-scale" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: 'query',
            contentType: 'application/json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            method:'post',
            cols: [[
                {type: "checkbox", width: 80},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'title',width: 300, title: '问卷标题'},
                // {field: 'echart', width: 80, title: 'ID'},

                // {field: 'url',width:500, title: '问卷URL'},
                // {field: 'starttime', width: 160, title: '开始时间'},
                // {field: 'endtime', width: 160, title: '结束时间'},
                {field: 'state', width: 140, title: '状态'},
                {field: 'admin', width: 140, title: '创建人',templet:'<div>{{d.admin.account}}</div>'},
                {field: 'createtime', minwidth: 160, title: '创建时间'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
      if (obj.event === 'preview'){ //监听预览问卷操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var arr=[];
                for(i in data){
                    arr[i]=data[i].id;
                }
                console.log(arr);
                if(arr.length!=1){
                    layer.msg("请选择一行数据修改");
                    return;
                }
                window.open("preview_echart/"+arr[0]);
            }
        });

    });
</script>

</body>
</html>
